package app

import (
	memoryRepository "ddd-practice/adapters/memory_repository"
	mockRepository "ddd-practice/adapters/mock_repository"
	"ddd-practice/app/command"
	"ddd-practice/app/query"
	"ddd-practice/domain"
)

type Application struct {
	Querys   Querys
	Commands Commands
}

type Querys struct {
	ProductAvailabilityHandler query.ProductAvailabilityHandler
	AllProductsHandler         query.AllProductsHandler
}

type Commands struct {
	PutOnShelvesHandler  command.PutOnShelvesHandler
	PutOffShelvesHandler command.PutOffShelvesHandler
}

func NewApplication() Application {

	repository := memoryRepository.NewProductMemoryRepository()
	return newApplication(repository)
}

func NewMockApplication() Application {

	repository := mockRepository.NewProductMockRepository()
	return newApplication(repository)
}

func newApplication(repository domain.Repository) Application {
	return Application{
		Querys: Querys{
			ProductAvailabilityHandler: query.NewProductAvailabilityHandler(repository),
			AllProductsHandler:         query.NewAllProductsHandler(repository),
		},
		Commands: Commands{
			PutOnShelvesHandler:  command.NewPutOnShelvesHandler(repository),
			PutOffShelvesHandler: command.NewPutOffShelvesHandler(repository),
		},
	}
}
